
public class Player {
	
	private Board board;
	private int points;
	private String name;
	private boolean direction; 
	private int locationX;
	private int locationY;
	private int delay;
	
	public Player(Board b){
	  this.board = b;
		this.points = 0;
		this.name = "";
		this.direction = true;
		locationX = 0;
		locationY = 0;
		this.delay = 0;
	}
	
	public void setPlayer() {
	  
	}
	
	public void setPlayer(int points) {
		this.points = points;
	}
	
	public void setPlayer(int points, String name) {
		this.points = points;
		this.name = name;
	}
	
	public void setPlayer(int points, String name, boolean direction) {
		this.points = points;
		this.name = name;
		this.direction = direction;
	}
	
	public void setPlayer(int points, String name, boolean direction, int locationX, int locationY) {
		this.points = points;
		this.name = name;
    this.direction = direction;
		setLocation(locationX, locationY);
	}
	
	public void setPlayer(int points, String name, boolean direction, int locationX, int locationY, int delay) {
		this.points = points;
		this.name = name;
		this.direction = direction;
		setLocation(locationX, locationY);
		this.delay = delay;
	}

	
	public int getPoints() {
		return points;
	}
	
	public void setPoints(int points) {
		this.points = points;
	}
	  
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public boolean getDirection() {
		return direction;
	}
	
	public void setDirection(boolean direction) {
		this.direction = direction;
	}
	
	public int getLocationX() {
		return locationX;
	}
	
	public int getLocationY(){
		return locationY;
	}
	
	public boolean setLocation(int x, int y) {
		if(checkLocation(x, y)) {
  		this.locationX = x;
  		this.locationY = y;
  		return true;
		}
		System.out.println("Error: Invalid location (" + x + ", " + y + ")");
	  return false;
	}
	
	public int getDelay() {
		return delay;
	}
	
	public void setDelay(int delay) {
	  this.delay = delay;
	}
	
	public boolean checkLocation(int x, int y) {
	  if((x == 0 || x == board.getWidth() - 1) && y >= 0 && y <  board.getHeight()) {
	    return true;
	  }
	  else if((y == 0 || y == board.getHeight() - 1) && x >=0 && x < board.getWidth()) {
	    return true;
	  }
	  return false;
	}
	
public void move(int steps){
		int width = board.getWidth();
		int height = board.getHeight();
		
		if(direction){
			//when the current position is when x = 0
			if(locationX == 0){
				if(steps > locationY){
					steps = steps - locationY;
					if(steps > width - 1){
						steps = steps - width + 1;
						if(steps > height - 1){
							steps = steps - height + 1;
							if(steps > width - 1){
								steps = steps - width + 1;
								if(steps > height -1){
								}else{
									locationY = height - steps - 1;
									locationX = 0;
								}
							}else{
								locationY = height - 1;
								locationX = width - steps -1;
							}
						}else{
							locationX = width - 1;
							locationY = steps;
						}
					}else{
						locationY = 0;
						locationX = steps;
					}
				}else{
					locationX = 0;
					locationY = locationY - steps;
				}
			}
			//when the start position is when x = width - 1
			else if(locationX == width -1){
				if(steps > height - locationY -1){
					steps = steps - height + locationY + 1;
					if(steps > width -1){
						steps = steps - width + 1;
						if(steps > height -1){
							steps = steps - height + 1;
							if(steps > width - 1){
								steps = steps - width + 1;
								if(steps > height - 1){
								}else{
									locationX = width - 1;
									locationY = steps;
								}
							}else{
								locationY = 0;
								locationX = steps;
							}
						}else{
							locationX = 0;
							locationY = height - steps -1;
						}
					}else{
						locationY = height -1;
						locationX = width - steps - 1;
					}
				}else{
					locationX = width -1;
					locationY = locationY + steps;
				}
			}
			//when the current position is y = 0
			else if(locationY == 0){
				if(steps > width - locationX - 1){
					steps = steps - width + locationX + 1;
					if(steps > height -1){
						steps = steps - height + 1;
						if(steps > width -1){
							steps = steps - width + 1;
							if(steps > height - 1){
								steps = steps - height + 1;
								if(steps > width -1){
								}else{
									locationY = 0;
									locationX = steps;
								}
							}else{
								locationX = 0;
								locationY = height - steps -1;
							}
						}else{
							locationX = width - steps - 1;
							locationY = height - 1;
						}
					}else{
						locationX = width -1;
						locationY = steps;
					}
				}else{
					locationY = 0;
					locationX = steps + locationX;
				}
			}
			//when the current position is at y = height - 1
			else{
				if(steps > locationX){
					steps = steps - locationX;
					if(steps > height - 1){
						steps = steps - height + 1;
						if(steps > width - 1){
							steps = steps - width + 1;
							if(steps > height -1){
								steps = steps - height + 1;
								if(steps > width - 1){
								}else{
									locationX = width - steps -1;
									locationY = height -1;
								}
							}else{
								locationX = width - 1;
								locationY = steps;
							}
						}else{
							locationY = 0;
							locationX = steps;
						}
					}else{
						locationX = 0;
						locationY = height - steps - 1;
					}
				}else{
					locationX = locationX - steps;
					locationY = height - 1;
				}
			}
		}
		//when the direction is counterclockwise
		else{
			if(locationX == 0){
				if(steps > height - locationY - 1){
					steps = steps - height + locationY + 1;
					if(steps > width - 1){
						steps = steps - width + 1;
						if(steps > height - 1){
							steps = steps - height + 1;
							if(steps > width - 1){
								steps = steps - width + 1;
								if(steps > height - 1){
									//test only
									System.out.println("Error in moving-5");
								}else{
									locationX = 0;
									locationY = steps;
								}
							}else{
								locationX = width - steps - 1;
								locationY = 0;
							}
						}else{
							locationX = width - 1;
							locationY = height - steps - 1;
						}
					}else{
						locationX = steps;
						locationY = height - 1;
					}
				}else{
					locationX = 0;
					locationY = locationY + steps;
				}
			}
			else if(locationX == width -1){
				if(steps > locationY){
					steps = steps - locationY;
					if(steps > width - 1){
						steps = steps - width + 1;
						if(steps > height - 1){
							steps = steps - height + 1;
							if(steps > width - 1){
								steps = steps - width + 1;
								if(steps > height - 1){
								}else{
									locationX = width -1;
									locationY = height - steps - 1;
								}
							}else{
								locationX = steps;
								locationY = height - 1;
							}
						}else{
							locationX = 0;
							locationY = steps;
						}
					}else{
						locationX = width - steps - 1;
						locationY = 0;
					}
				}else{
					locationY = locationY - steps;
					locationX = 2;
				}
			}
			else if(locationY == 0){
				if(steps > locationX){
					steps = steps - locationX;
					if(steps > height -1){
						steps = steps - height + 1;
						if(steps > width -1){
							steps = steps - width + 1;
							if(steps > height - 1){
								steps = steps - height + 1;
								if(steps > width - 1){
								}else{
									locationX = width - steps - 1;
									locationY = 0;
								}
							}else{
								locationX = width - 1;
								locationY = height - steps - 1;
							}
						}else{
							locationX = steps;
							locationY = height - 1;
						}
					}else{
						locationX = 0;
						locationY = steps;
					}
				}else{
					locationY = 0;
					locationX = locationX - steps;
				}
			}
			else{
				if(steps > width - locationX - 1){
					steps = steps - width + locationX + 1;
					if(steps > height - 1){
						steps = steps - height + 1;
						if(steps > width - 1){
							steps = steps - width + 1;
							if(steps > height - 1){
								steps = steps - height + 1;
								if(steps > width){
								}else{
									locationX = steps;
									locationY = height - 1;
								}
							}else{
								locationX = 0;
								locationY = steps;
							}
						}else{
							locationX = width - steps - 1;
							locationY = 0;
						}
					}else{
						locationX = width - 1;
						locationY = height - steps - 1;
					}
				}else{
					locationY = height -1;
					locationX = locationX + steps;
				}
			}
		}
  }
}
